<html>
	<head>
		<script src="../../src/gears_init.js"></script>
		<script src="../../src/Norm.js"></script>
		<script src="../../src/Norm.Logger.Gears.js"></script>
		<script src="../../src/Norm.Database.Gears.js"></script>
		<script src="../../src/Norm.ResultIterator.Gears.js"></script>
		<script src="../../src/Norm.LastIdManager.js"></script>
		<script src="../../src/Norm.Events.js"></script>
		<script src="../../src/Norm.Sql.js"></script>
		<script src="../../src/Norm.Fields.js"></script>
		<script src="../../src/Norm.Model.js"></script>
		<script src="../../src/Norm.Introspection.js"></script>
		<script src="../../src/Norm.Transaction.js"></script>
		<script>
			Norm.Database.name = "test.simple1";
			var Person = new Norm.Model({
				name : "Person",
				fields : {
					firstName : new Norm.Fields.String({maxLength : 25}),
					lastName : new Norm.Fields.String({maxLength : 25})
				}
			});
			
			//testInsertSelect();
			
			var Tests = {
				
				up : function() {
					
					Person.dropTable();
					Person.createTable();
				},
				
				"test if create works" : function() {
					
					var someone = new Person();
					someone.firstName = "John";
					someone.lastName = "Doe";
					someone.save();
					UnitTest.assertDefined(someone.rowid, "someone wasn`t inserted");
				},
				
				"test if retrive using constructor work" : function() {
					
					var someone = new Person(1);
					UnitTest.assertTrue(someone.firstName == "John", "first name is wrong");
					UnitTest.assertTrue(someone.lastName == "Doe", "last name is wrong");
				},
				
				"test if update works" : function() {
					
					var someone = new Person(1);
					someone.firstName = "updated";
					someone.save();
					var fromDb = new Person(1);
					UnitTest.assertTrue(fromDb.firstName == "updated", "someone wasn`t updated");
				},
				
				"test if count works" : function() {
					
					UnitTest.assertEqual(1, Person.count());
					new Person({firstName : "test", lastName : "test"}).save();
					UnitTest.assertEqual(2, Person.count());
					UnitTest.assertEqual(1, Person.count("firstName = ?", ["test"]));
				},
				
				"test if delete works" : function() {
					
					var someone = Person.select().getOne();
					var id = someone.rowid;
					someone.remove();
					UnitTest.assertTrue(
						Person.select("rowid = ?", [id]).getOne() == false,
						"someone wasn`t delete"
					); 
				},
				
				down : function() {
					Person.dropTable();
				}
			};
		</script>
		<script src="unit-test.js"></script>
	</head>
	<body>
		
	</body>
</html>